package com.cmas.platform.controller;

import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import com.aidex.common.annotation.DataSource;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.TableDataInfo;
import com.aidex.common.core.page.PageDomain;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aidex.common.enums.BusinessType;
import com.aidex.common.enums.DataSourceType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.common.core.controller.BaseController;
import com.aidex.framework.cache.DictUtils;

import javax.validation.constraints.*;

import com.cmas.platform.vo.RegionMapVo;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.cmas.platform.domain.RegionMap;
import com.cmas.platform.service.RegionMapService;


/**
 * 地区地图Controller
 *
 * @author su
 * @email 1218819874@qq.com
 * @date 2023-03-14
 */
@DataSource(value = DataSourceType.SLAVE)
@RestController
@RequestMapping("/platform/regionMap")
public class RegionMapController extends BaseController {

    @Autowired
    private RegionMapService regionMapService;

    /**
     * 查询地区地图列表
     */
    @PreAuthorize("@ss.hasAnyPermi('platform:regionMap:list,platform:region:list')")
    @GetMapping("/list")
    public R<TableDataInfo> list(RegionMap regionMap) {
        startPage();
        List<RegionMapVo> list = regionMapService.selectRegionMapVoList(regionMap);
        return R.data(getDataTable(list));
    }

    /**
     * 获取地区地图详细信息
     */
    @PreAuthorize("@ss.hasAnyPermi('platform:regionMap:query,platform:region:query')")
    @GetMapping(value = "/{id}")
    public R<RegionMap> detail(@PathVariable("id") String id) {
        return R.data(regionMapService.getById(id));
    }

    /**
     * 新增地区地图
     */
    @PreAuthorize("@ss.hasPermi('platform:regionMap:add')")
    @Log(title = "地区地图", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated RegionMap regionMap) {
        if (regionMapService.addRegionMap(regionMap)) {
            return R.success("新增成功");
        }
        return R.fail("新增失败");
    }

    /**
     * 修改地区地图
     */
    @PreAuthorize("@ss.hasAnyPermi('platform:regionMap:edit,platform:region:edit')")
    @Log(title = "地区地图", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated RegionMap regionMap) {
        return R.data(regionMapService.updateRegionMap(regionMap));
    }

    /**
     * 删除地区地图
     */
    @PreAuthorize("@ss.hasPermi('platform:regionMap:remove')")
    @Log(title = "地区地图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.data(regionMapService.deleteRegionMapByIds(ids));
    }


    /**
     * 导出地区地图列表
     */
    @PreAuthorize("@ss.hasPermi('platform:regionMap:export')")
    @Log(title = "地区地图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(RegionMap regionMap) {
        List<RegionMap> list = regionMapService.selectRegionMapList(regionMap);
        ExcelUtil<RegionMap> util = new ExcelUtil<RegionMap>(RegionMap.class);
        return util.exportExcel(list, "地区地图数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

    // ***用户系统位置戳****

    /**
     * 查询地区地图列表
     */
    @GetMapping("/onlineRegionMap")
    public R<?> onlineRegionMap(RegionMapVo regionMapVo) {
        List<RegionMapVo> list = regionMapService.getOnlineRegionMap(regionMapVo);
        return R.data(list);
    }


}
